﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Configuration;

namespace nanoCMS.Core.Helpers
{
    class EmailHelper
    {
        public void SendEmail(string address, string subject, string message)
        {
            string email = ConfigurationManager.AppSettings.Get("email");
            string password = ConfigurationManager.AppSettings.Get("password");
            string client = ConfigurationManager.AppSettings.Get("client");
            string port = ConfigurationManager.AppSettings.Get("port");

            NetworkCredential loginInfo = new NetworkCredential(email, password);
            MailMessage msg = new MailMessage();
            SmtpClient smtpClient = new SmtpClient(client, int.Parse(port));

            msg.From = new MailAddress(email);
            msg.To.Add(new MailAddress(address));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;

            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;
            smtpClient.Send(msg);
        }
    }
}
